#ifndef FILEWIDGET_H
#define FILEWIDGET_H

#include <QWidget>
#include "delegate.h"
#include "delegateTemplate.h"
#include <QTableView>
#include <QPushButton>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QTextEdit>
#include <QLabel>
#include <QDomDocument>
#include <QRadioButton>

class QStandardItem;

class fileWidget : public QWidget
{
    Q_OBJECT
public:
    fileWidget(QWidget *parent = 0);
    ~fileWidget();

    bool open();
    bool save();
    bool saveAs();
    bool openFileToCompare();
    void compare();
    void updateTemplateWidget();
public slots:
    void openXML();
protected:
    void closeEvent(QCloseEvent *event);
private slots:
    void setOffset(QModelIndex index);
    void setOffsetToCompare(QModelIndex index);
    void setMainWindowModified(QStandardItem *);
    void setByteOrder(QAbstractButton *button);
private:
    bool loadFile(const QString &fileName);
    bool loadFileToCompare(const QString &fileToCompareName);
    void createWidgetFromTemplate(const QString &XMLFileName);
    bool saveFile();

    QWidget *parent;
    QDataStream::ByteOrder byteOrder;
    QButtonGroup *buttonGroup;
    QRadioButton *radioButtonL;
    QRadioButton *radioButtonB;

    QTextEdit *textEdit;
    //QTextEdit *textEditHex;
    QString fileName;
    quint64 offset;
    QString XMLFileName;
    QByteArray array;
    QStandardItemModel *model;
    QStandardItemModel *TemplateModel;
    QTableView *tableView;
    QTableView *TemplateTableView;
    delegate *lineEdit;
    delegateTemplate *templateDelegate;
    //QPushButton *button;
    QDomDocument doc;
    //QHBoxLayout *layout;
    QGridLayout *layout;
    QVBoxLayout *verticalLayout;
    //QLabel *label;

    QString fileToCompareName;
    QGridLayout *layoutToCompare;
    QByteArray arrayToCompare;
    QStandardItemModel *modelToCompare;
    QTableView *tableViewToCompare;
    delegate *lineEditToCompare;
    quint64 offsetToCompare;

    QModelIndex indexToCompare;
    QModelIndex indexToCompare2;
};

#endif // FILEWIDGET_H
